package com.csit.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name="T_User")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User implements Serializable {

	private static final long serialVersionUID = -3710570690813540122L;
	
	//登录用户ID
	public static final String LOGINID = "loginID";
	//登录用户角色
	public static final String LOGINTYPE ="loginType";
	//登录用户名称
	public static final String LOGINNAME = "loginName";
	
	public static final String USERSHOP = "userShop";
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Integer userID;
	
	@Column(length=50,unique=true)
	private String userCode;
	
	@Column(length=50)
	private String userName;
	
	@Column(length=50)
	private String password;
	//0 :店员  1: 店长 2：老板
	private Integer roleType;
	//属于那家店面
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="ShopID")
	private DataDictionary shop;

	public Integer getUserID() {
		return userID;
	}

	public void setUserID(Integer userID) {
		this.userID = userID;
	}

	public String getUserCode() {
		return userCode;
	}

	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Integer getRoleType() {
		return roleType;
	}

	public void setRoleType(Integer roleType) {
		this.roleType = roleType;
	}

	public DataDictionary getShop() {
		return shop;
	}

	public void setShop(DataDictionary shop) {
		this.shop = shop;
	}
	
	@Transient
	public Integer getShopID(){
		if(shop==null){
			return null;
		}
		return shop.getDataDictionaryID();
	}
	
	@Transient
	public String getShopName(){
		if(shop==null){
			return null;
		}
		return shop.getDataDictionaryName();
	}
	
	@Transient
	public void setShopID(Integer shopID){
		if(shop==null){
			shop = new DataDictionary();
		}
		shop.setDataDictionaryID(shopID);
	}

}
